package com.lzy.concertticket.task;

import com.lzy.concertticket.cache.FlowCache;
import com.lzy.concertticket.dao.FlowDao;
import com.lzy.concertticket.model.entity.FlowEntity;
import com.lzy.concertticket.service.FlowService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Component
public class FlowTaskService {

    @Autowired
    private FlowService flowService;

    @Scheduled(fixedRate = 5000)
    public void saveFlowBatch() {
        if (FlowCache.hasFlow()) {
            List<FlowEntity> flowEntityList = FlowCache.cutFlow(100);
            flowService.saveBatch(flowEntityList);
        }
    }


}
